package stream;

import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.Random;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class StreamTest {
    public static void main(String[] args) {
        List<Character> CHAR = Stream.concat(
                Stream.iterate('A', c -> (char) (c + 1)).limit(26),
                Stream.iterate('0', c -> (char) (c + 1)).limit(10)
        ).toList();
        System.out.println(CHAR);

        Random random = new Random();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < 6; i++) {
            sb.append(CHAR.get(random.nextInt(CHAR.size())));
        }
        System.out.println(sb);

        List<Item> items = Stream.generate(() -> new Item(random.nextInt(20)))
                .limit(20)
                .collect(Collectors.toList());
//        System.out.println(items);
        items
                .parallelStream()
                .filter(Objects::nonNull)
                .sorted(Comparator.comparingInt(o -> o.count))
                .peek(item -> System.out.print(item + " "))
                .forEach(item -> {
                    if (item.count > 10) {
                        item.count = 0;
                    }
                    System.out.println(item);
                });
        System.out.println(items);
    }

    static class Item {
        int count;

        public Item(int count) {
            this.count = count;
        }

        @Override
        public String toString() {
            return "Item{" +
                    "count=" + count +
                    '}';
        }
    }
}
